class BankAccount1{
    //初始化
    private String accountname;
    private double balance;
    //修改成员变量 this.
    public void setAccountname(String accountname){
        this.accountname=accountname;
    }
    //使用方法返回账户
    public String getAccountname(){
        return accountname;
    }
    //方法判断输入余额不能少于0
    public void setBalance(double balance){
        if (balance<0){
            System.out.println("输入金额有误!");
        }else{
            this.balance=balance;
        }

    }
    //返回余额的方法
    public double getBalance(){
        return balance;
    }
    //打印账户和余额
    public void broadcast(String accountname,double balance){
        System.out.println("账户"+accountname+"的余额为"+balance+"元");
    }
}
public class Example04{
    public static void main(String[]args){
        BankAccount1 ac1=new BankAccount1();
        ac1.setAccountname("123456");
        ac1.setBalance(-500);
        //得到账户名和余额，使用broadcast返回
        ac1.broadcast(ac1.getAccountname(),ac1.getBalance());
    }
}




